package jue;

import java.util.concurrent.locks.ReentrantLock;

public class Lock锁 {
    static int j;

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                lock.lock();
                try {
                    j++;
                } finally {
                    lock.unlock();
                }


            }).start();
        }
        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                lock.lock();
                try {
                    j--;
                } finally {
                    lock.unlock();
                }
            }).start();
        }

    }
}
